import request from '@/utils/request'
import axiosReq from "@/utils/axiosReq";

export function apiGetNew() {
    return request({
        api: "mgop.linewell.eraq.supplyNew",
        url: "/api/eraq/supply/new",
        method: 'get'
    });
}

export function apiGetDetail(unid) {
    return request({
        api: "mgop.linewell.eraq.supplyDetail",
        url: "/api/eraq/supply/detail",
        method: 'get',
        params: {
            unid
        }
    });
}

export function apiGetInfo(unid) {
    return request({
        api: "mgop.linewell.eraq.supplyInfo",
        url: "/api/eraq/supply/info",
        method: 'get',
        params: {
            unid
        }
    });
}


export function apiSaveAuthId(unid, authId) {
    return request({
        api: "mgop.linewell.eraq.supplyAuth2",
        url: "/api/v2/qrcode/auth",
        method: 'post',
        params: {
            unid, authId
        },
        loadText: "保存中..."
    });
}

export function apiQrcodeLogin(unid) {
    return axiosReq({
        url: "/api/v2/qrcode/login?unid=" + unid,
        //url: "/api/qrcode/login?unid=" + unid,
        method: 'get',
        headers: {
            isToken: false
        },
    });
}

export function apiSavePcAuthId(unid, authId) {
    return axiosReq({
        url: "/api/v2/qrcode/auth?unid=" + unid + "&authId=" + authId,
        //url: "/api/qrcode/auth?unid=" + unid + "&authId=" + authId,
        method: 'get',
        headers: {
            isToken: false
        },
    });
}

export function getQrcode(unid) {
    return request({
        api: "mgop.linewell.eraq.supplyQrcode",
        url: "/api/eraq/supply/qrcode",
        method: 'get',
        params: {
            unid
        },
    });
}

export function apiReqEntNames(name, cb) {
    if (name === null || name === "" || name.length < 3) {
        cb([]);
        return;
    }

    request({
        api: "mgop.linewell.eraq.enterprise",
        url: "/api/eraq/enterprise",
        method: 'get',
        params: {
            name
        }
    }).then(response => {
        if (response === null || response.code !== 200) {
            cb([]);
            return;
        }
        let results = [];
        for (var i = 0, n = response.data.length; i < n; i++) {
            results.push({
                "value": response.data[i]
            });
        }
        cb(results);
    }).catch(() => {
        cb([]);
    });
}

export function apiSaveBase(entName) {
    return request({
        api: "mgop.linewell.eraq.supplyBase",
        url: "/api/eraq/supply/base",
        method: 'post',
        params: {
            applyfrom: "移动端",
            unitName: entName
        },
        loadText: "提交中...",
    });
}

export function apiSaveChange(entName) {
    return request({
        api: "mgop.linewell.eraq.supplyChange",
        url: "/api/eraq/supply/change",
        method: 'post',
        params: {
            applyfrom: "移动端",
            unitName: entName,
        },
        loadText: "提交中..."
    });
}

export function apiSaveinner(unid, entNames, userType, mobile) {
    return request({
        api: "mgop.linewell.eraq.supplyInner2",
        url: "/api/v2/eraq/supply/inner",
        method: 'post',
        params: {
            unid,
            usertype: userType,
            applyfrom: "移动端",
            unitName: entNames.toString(),
            mobile
        },
        loadText: "提交中..."
    });
}

export function apiGetList(page) {
    return request({
        api: "mgop.linewell.eraq.supply",
        url: "/api/eraq/supply",
        method: 'get',
        params: {
            page
        },
        loadText: "加载中..."
    });
}

//补正补齐提交
export function apiDoPatch(unid) {
    return request({
        api: "mgop.linewell.eraq.supplyPatch",
        url: "/api/eraq/supply/patch",
        method: 'post',
        params: {
            unid
        },
        loadText: "提交中..."
    });
}

//重新提交
export function doSupply(unid) {
    return request({
        api: "mgop.linewell.eraq.supplyPush",
        url: "/api/eraq/supply/push",
        method: 'post',
        params: {
            unid
        },
        loadText: "提交中..."
    });
}

//获得企业基本信息
export function apiGetEntInfo(unitName) {
    return request({
        api: "mgop.linewell.eraq.supplyEnt2",
        url: "/api/v2/eraq/supply/ent",
        method: 'get',
        params: {
            unitName
        },
    });
}

//获取人脸识别二维码
export function apiGetFaceReuquestId(params) {
    return request({
        api: "mgop.linewell.eraq.supplyQrcode2",
        url: "/api/v2/qrcode",
        method: 'get',
        params
    });
}



